package org.check.UI;

import java.awt.EventQueue;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;

import org.check.SQL.ConnectionPool;
import org.check.UI.DateChooserPanel.defaultDates;
import org.check.Util.XmlParser;
import org.check.VO.DBConnVO;

import net.miginfocom.swing.MigLayout;

public class MainUI {

	MainUI mainUI = this;
	private JFrame frmvBeta;

	int[] selectedCols;
	int newSelectCol;

	private List<DBConnVO> dbConnVOs;
	private final String conns_config = "conns_config.xml";

	List<String> colList = new LinkedList<String>();
	
	static ConnectionPool connPool = null;

	// location data initialize-----------

	private DBConnSelectPanel dbConnSelectPanel;
	private QuickConfigPanel quickConfigPanel;
	private ColSelectPanel colSelectPanel;
	private DateChooserPanel dataDateChooserPanel;
	private DateChooserPanel courseDateChooserPanel;
	private ContactPanel contactPanel;
	private CourseTypeSelectPanel courseTypeSelectPanel;
	private IDFilterPanel idFilterPanel;
	private ExportXlsPanel exportXlsPanel;
	private DoQueryPanel doQueryPanel;
	private DataPreviewPanel dataPreviewPanel;

	// data value initialize-----------

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainUI window = new MainUI();
					window.frmvBeta.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainUI() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	/**
	 * 
	 */
	private void initialize() {
		// component initialize-----------
		dbConnVOs = XmlParser.generateDBVOList(conns_config);
		frmvBeta = new JFrame();
		frmvBeta.setTitle("查数工具V2.0 beta");
		frmvBeta.setBounds(0, 0, 1024, 768);
		frmvBeta.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmvBeta.getContentPane()
				.setLayout(new MigLayout("insets 0",
						"[158.00px:n,fill]0[162.00,grow]0[100px:165.00]0[100px:n:1200px,grow 600,shrink 400]0[100px:n:300px]",
						"[36px,fill]0[36px,fill]0[31.00,top]0[555.00px,grow]"));
	
		colSelectPanel = new ColSelectPanel();
		exportXlsPanel = new ExportXlsPanel(colSelectPanel);
		quickConfigPanel = new QuickConfigPanel(dbConnVOs,exportXlsPanel);
		dbConnSelectPanel = new DBConnSelectPanel(dbConnVOs,quickConfigPanel);
		dataDateChooserPanel = new DateChooserPanel(defaultDates.data,exportXlsPanel);
		courseDateChooserPanel = new DateChooserPanel(defaultDates.course,exportXlsPanel);
		contactPanel = new ContactPanel();
		courseTypeSelectPanel = new CourseTypeSelectPanel();
		idFilterPanel = new IDFilterPanel();
		dataPreviewPanel = new DataPreviewPanel();
		quickConfigPanel.repaintQuickConfig(0);
		doQueryPanel = new DoQueryPanel(quickConfigPanel, colSelectPanel, idFilterPanel.filterCourseId(), courseTypeSelectPanel.getCourseType(),  dataPreviewPanel, dataDateChooserPanel, courseDateChooserPanel);
		
		
		frmvBeta.getContentPane().add(dbConnSelectPanel, "cell 0 0 4 1,grow");
		frmvBeta.getContentPane().add(contactPanel, "cell 4 0 1 2,grow");
		frmvBeta.getContentPane().add(exportXlsPanel, "cell 0 1 4 1,grow");
		frmvBeta.getContentPane().add(dataPreviewPanel, "cell 1 3 4 1,grow");

		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBackground(UIManager.getColor("TabbedPane.background"));
		tabbedPane.setBorder(null);
		frmvBeta.getContentPane().add(tabbedPane, "cell 0 2 2 1,grow");
		tabbedPane.addTab("数据区间", null, dataDateChooserPanel, null);
		tabbedPane.addTab("课程创建时间", null, courseDateChooserPanel, null);
		
		JTabbedPane tabbedPane_1 = new JTabbedPane(JTabbedPane.TOP);
		frmvBeta.getContentPane().add(tabbedPane_1, "cell 3 2 2 1,grow");
		tabbedPane_1.addTab("进行查询", null, doQueryPanel, null);

		JTabbedPane tabbedPane_2 = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane_2.setBackground(UIManager.getColor("TabbedPane.background"));
		frmvBeta.getContentPane().add(tabbedPane_2, "cell 0 3,grow");
		tabbedPane_2.addTab("数据选择", null, colSelectPanel, null);
		tabbedPane_2.addTab("快速配置", null, quickConfigPanel, null);
		
		JTabbedPane tabbedPane_3 = new JTabbedPane(JTabbedPane.TOP);
		frmvBeta.getContentPane().add(tabbedPane_3, "cell 2 2,grow");
		
		tabbedPane_3.addTab("ID过滤", null, idFilterPanel, null);
		tabbedPane_3.addTab("课程类别", null, courseTypeSelectPanel, null);

		Calendar c = Calendar.getInstance();
		c.add(Calendar.YEAR, -10);

	}

}
